package com.nbsaas.boot.script;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

public class FileScriptSource implements ScriptSource {

    @Override
    public String getPrefix() {
        return "file:";
    }

    @Override
    public String loadScript(String path) throws Exception {
        String actual = path.startsWith(getPrefix()) ? path.substring(getPrefix().length()) : path;
        File file = new File(actual);
        if (!file.exists()) {
            throw new IllegalArgumentException("文件不存在: " + actual);
        }
        return Files.readString(file.toPath(), StandardCharsets.UTF_8);
    }
}
